<?php
defined("_AS") or die("No se permite el acceso directo a este archivo");

/**
* Checks the user agent string against known browsers
*/
function getNavegador( $agent ) {
	require( "../includes/agent_browser.php" );

	if (preg_match( "/msie[\/\sa-z]*([\d\.]*)/i", $agent, $m )
	&& !preg_match( "/webtv/i", $agent )
	&& !preg_match( "/omniweb/i", $agent )
	&& !preg_match( "/opera/i", $agent )) {
		// IE
		return "MS Internet Explorer $m[1]";
	} else if (preg_match( "/netscape.?\/([\d\.]*)/i", $agent, $m )) {
		// Netscape 6.x, 7.x ...
		return "Netscape $m[1]";
	} else if ( preg_match( "/mozilla[\/\sa-z]*([\d\.]*)/i", $agent, $m )
	&& !preg_match( "/gecko/i", $agent )
	&& !preg_match( "/compatible/i", $agent )
	&& !preg_match( "/opera/i", $agent )
	&& !preg_match( "/galeon/i", $agent )
	&& !preg_match( "/safari/i", $agent )) {
		// Netscape 3.x, 4.x ...
		return "Netscape $m[2]";
	} else {
		// Other
		$found = false;
		foreach ($browserSearchOrder as $key) {
			if (preg_match( "/$key.?\/([\d\.]*)/i", $agent, $m )) {
				$name = "$browsersAlias[$key] $m[1]";
				return $name;
				break;
			}
		}
	}

	return 'Unknown';
}

/**
* Checks the user agent string against known operating systems
*/
function getSO( $agent ) {
	require( "../includes/agent_os.php" );

	foreach ($osSearchOrder as $key) {
		if (preg_match( "/$key/i", $agent )) {
			return $osAlias[$key];
			break;
		}
	}

	return 'Unknown';
}

/**
 *
*/

function getIP(){
	if($_SERVER["HTTP_X_FORWARDED_FOR"]){
		if($pos = strpos($_SERVER["HTTP_X_FORWARDED_FOR"]," ")){
			$iplocal   = substr($_SERVER["HTTP_X_FORWARDED_FOR"],0,$pos);
			$ippublica = substr($_SERVER["HTTP_X_FORWARDED_FOR"],$pos+1);
			$hostlocal = substr($_SERVER["HTTP_X_FORWARDED_FOR"],$pos+1);
		}else{
			$ippublica = $_SERVER["HTTP_X_FORWARDED_FOR"];
			$hostlocal =$_SERVER["HTTP_X_FORWARDED_FOR"];
		}
		if($_SERVER["REMOTE_ADDR"])
			$proxy = $_SERVER["REMOTE_ADDR"];
	}else{
		$ippublica = $_SERVER["REMOTE_ADDR"];
		$hostlocal = $_SERVER["REMOTE_ADDR"];
		if($hostlocal!=$_SERVER["REMOTE_ADDR"])
			$hostname = $hostlocal;
	}
	$hostname = gethostbyaddr($hostlocal);
	if($hostlocal!=$hostname)
		$hostname = $hostname;
 
	if($iplocal == '') $iplocal = '[no disponible]';
	if($ippublica == '') $ippublica = '[no disponible]';
	if($ipproxy == '') $ipproxy = '[no disponible]';
	if($hostname == '') $hostname = '[no disponible]';
	
	$arrip[] = $iplocal;
	$arrip[] = $ippublica;
	$arrip[] = $proxy;
	$arrip[] = $hostname;
	return $arrip;
}
?>